package cn.virens.web.controller.manage.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.virens.common.RequestUtil;
import cn.virens.components.page.PageParamUser;
import cn.virens.components.page.PageResult;
import cn.virens.database.enums.log.LogLevel;
import cn.virens.database.enums.log.LogType;
import cn.virens.database.mysql.model.sys.SysLog;
import cn.virens.service.inter.sys.SysLogService;
import cn.virens.web.common.BaseTableController;

/**
 * 日志管理 - sys_log
 *
 * @author Virens
 * @since  2018-08-25 15:36:58
 */
@Controller
@RequestMapping("/manage/sys/log")
public class SysLogContorller extends BaseTableController<SysLog, SysLogService> {

	public SysLogContorller() {
		super("/manage/sys/log", "sys:log");
		super.disable(API_CREATE, API_UPDATE, API_DELETE);
	}

	@Override
	public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		String answer = super.index(request, response, model);
		model.addAttribute("levels", LogLevel.values());
		model.addAttribute("types", LogType.values());

		return answer;
	}

	@Override
	protected PageResult<?> listHandle(HttpServletRequest request, PageParamUser pageParam) throws Exception {
		pageParam.addParam("level", RequestUtil.getValueInt(request, "level", null));
		pageParam.addParam("type", RequestUtil.getValueInt(request, "type", null));
		pageParam.addParam("user", RequestUtil.getValueStr(request, "user", null));
		pageParam.setOrderBy("id DESC");

		return super.listHandle(request, pageParam);
	}
}
